<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@include file="/common/public.jsp" %>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>库存列表</title>
    <script type="text/javascript" src="${ctx}/js/page.js"></script>
    <script type="text/javascript" src="${ctx}/js/search.js"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            getPartList();
            exportTable();
            //搜索
            $("#find").click(function(){
                var condition=$("#condition").val();
                var url2="${ctx}/intStore/getFList?condition="+condition;
                if(condition==""){
                    getPartList();
                }else{
                    search.cseatch(url2);
                }
            });

            //完成编辑
            $("#finish").click(function(){
                if(confirm("提交后不可以再新增")){
                   $("#add").hide();
                    $("#finish").hide();
                    var url="${ctx}/intStore/finish";
                    $.get(url,function(data,status){
                        alert(data);
                    });
                }
            });

            var status=Number($("#status").val());
            if(status==1){
                $("#add").hide();
                $("#finish").hide();
            }else {
                $("#add").show();
                $("#finish").show();
            }
        });
    </script>

    <script type="text/javascript">
        function getPartList(){
            var url = "${ctx}/intStore/getLimitList";
            var count = $("#count").val();
            page.pagePart(url, count);
        }
        function customPage(obj) {
            $("#table tr:gt(1)").remove();
            for (var i = 0; i < obj.length; i++) {
                var status=Number(obj[i].status);
                if (status==1) {
                    status = "已入库";
                } else {
                    status = "未入库";
                }
                var newRow = "<tr>" +
                        "<td>" + obj[i].intId + "</td><td>" + obj[i].userName + "</td>" +
                        "<td>" + obj[i].foodBarCode + "</td><td>" + obj[i].foodName + "</td>" +
                        "<td>" + obj[i].foodStandard + "</td><td>" + obj[i].className + "</td>" +
                        "<td>" + obj[i].foodNum + "</td>"  +
                        "<td>" + obj[i].providerName + "</td>"  +
                        "<td>" + obj[i].overDate + "</td>"  +
                        "<td>" + status + "</td>" + "<td>" + obj[i].remarks + "</td>" +  "<td>";

                if(window.userPower==0||window.userPower==34){
                    newRow=newRow+   "<a id='edit" + i + "' href='${ctx}/intStore/editStore?id=" + obj[i].intId + "'>修改&nbsp;&nbsp;</a>" +
                    "<a id='delete" + i + "' href='${ctx}/intStore/delete?id=" + obj[i].intId + "'>删除&nbsp;&nbsp;</a>" +
                    "</td></tr>";
                }

                $("#table tr:last").after(newRow);
            }

        }
    </script>


</head>

<body>
<input type="hidden" id="count" value="${count}">
<input type="hidden" id="status" value="${status}">
<div class="pagin">
    <br/>
    <input type="hidden" value="${type}" id="type">
    <br/> <br/>
    <a id="add" href="${ctx}/intStore/add?type=${type}">新增</a>
    <input type="text" id="condition" placeholder="请输入ID或者名称"><button id="find">搜索</button>
    <button id="export">导出</button>
    <br/><br/>
    <table id="table" class="t1" style="width: 80%">
        <tr><%--<th colspan="15">采购列表</th>--%>
            <c:if test="${type==1}">
                <th colspan="16">进货列表</th>
            </c:if>
            <c:if test="${type==2}">
                <th colspan="16">退货列表</th>
            </c:if>
        </tr>

        <tr>
            <c:if test="${type==1}">
                <td>进货ID</td>
            </c:if>
            <c:if test="${type==2}">
                <td>退货ID</td>
            </c:if>
            <td>员工姓名</td>
            <td>食品条码</td>
            <td>食品名称</td>
            <td>食品规格</td>
            <td>食品分类</td>
            <c:if test="${type==1}">
                <td>进货量</td>
            </c:if>
            <c:if test="${type==2}">
                <td>退货量</td>
            </c:if>
            <td>供应商</td>
            <td>过期时间</td>
            <td>状态</td>
            <td>备注</td>
            <td>操作</td>
        </tr>
    </table>


    <br/>

    <div id="Pagination" class="pagination"
         style=" width: -moz-fit-content;width:-webkit-fit-content;width: fit-content;margin-left: auto;margin-right: auto;"></div>
</div>
<br/><br/>
<button id="finish">完成</button>
</body>
</html>